import { reqC1List, reqC2List, reqC3List } from "@/api/product/attr/attr";
import { defineStore } from "pinia";
import type { categoryStoreStateType } from "./interface/category";

const useCategoryStore = defineStore('category', {
    state: ():categoryStoreStateType => {
        return {
            // 一级分类
            c1List: [],
            c1Id: '',
            c2List: [],
            c2Id: '',
            c3List: [],
            c3Id: '',
        }
    },


    actions: {
        // 获取一级分类的数据
        async getC1List() {
            let result = await reqC1List()
            this.c1List = result
           
        },
        // 获取二级分类的数据
        async getC2List() {
            this.c2Id = ''
            this.c2List = []
            this.c3Id = ''
            this.c3List = []
            let result = await reqC2List(this.c1Id)
            this.c2List = result
           
        },
        // 获取三级分类的数据
        async getC3List() {
            this.c3Id = ''
            this.c3List = []
            let result = await reqC3List(this.c2Id)
            this.c3List = result
            
        }
    }
})

export default useCategoryStore